package com.hp.bon.sgw.wh.channel.outside;

import com.hp.bon.sgw.wh.channel.common.BizConsts;
import com.hp.bon.sgw.wh.channel.common.BizParam;
import com.hp.bon.sgw.wh.channel.outside.bizSlotOutQuery.PayBlackOweBizSlot;
import com.hp.bon.sgw.wh.channel.outside.bizSlotOutQuery.QueryBlackOweBizSlot;
import com.hp.bon.sgw.wh.channel.outside.bizSlotOutQuery.QueryStopNetBizSlot;
import com.hp.bon.sgw.wh.channel.outside.bizSlotOutQuery.RechargeExtractBizSlot;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

public class OutApiBizRouter {

	private static final Logger _log = LoggerFactory.getLogger(OutApiBizRouter.class);

	private Map<String, BizSlot> slotRepositories = new HashMap<String, BizSlot>();

	public void init() {
		
		//2.5.1	下游HTTP消息配置地址参数
		// 断网查询  QueryStopNet.HB
		BizSlot bizSlot = new QueryStopNetBizSlot();
		slotRepositories.put("QueryStopNet.HB", bizSlot);
		// 拆机欠费查询 QueryBlackOwe.HB
		bizSlot = new QueryBlackOweBizSlot();
		slotRepositories.put("QueryBlackOwe.HB", bizSlot);
		// 拆机用户缴费 PayBlackOwe.HB
		bizSlot = new PayBlackOweBizSlot();
		slotRepositories.put("PayBlackOwe.HB", bizSlot);
		// 翼支付充值  PayBlackOwe.HB
		bizSlot = new RechargeExtractBizSlot();
		slotRepositories.put("RechargeExtract.BestPay", bizSlot);

	}

	public BizSlot doRouter(BizParam bizParam) {
		String capability = bizParam.getParamString(BizConsts.KEY_API_CAPABILITY);
		BizSlot bizSlot = slotRepositories.get(capability);
		if (null == bizSlot) {
			_log.error("none bizSlot,capability={},", capability);
			Set<Entry<String, BizSlot>> entries = slotRepositories.entrySet();
			for (Entry<String, BizSlot> entry : entries) {
				_log.info("bizSlot, key={}, clz={}", entry.getKey(), entry.getValue().getClass());
			}
		}
		return bizSlot;
	}

}
